widget: Reshuffle code for style context getter
authorBenjamin Otte <otte@redhat.com>
Sat, 26 Mar 2011 15:07:54 +0000 (16:07 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 26 Mar 2011 23:48:25 +0000 (00:48 +0100)
The intention of this patch is to make the code clearer, shorter and
most of all to avoid recreating the widget path and setting it path
twice on the style context when the style context was recreated.

gtk/gtkwidget.c

index f52ac29dde86452aac85e5f10dde8d3dad972237..03fde1535cb2f32ac55ae41c18d683fc440121be 100644 (file)
@@ -14330,15 +14330,23 @@ style_context_changed (GtkStyleContext *context,
 GtkStyleContext *
 gtk_widget_get_style_context (GtkWidget *widget)
 {
+  GtkWidgetPrivate *priv;
+  GtkWidgetPath *path;
+
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  if (G_UNLIKELY (!widget->priv->context))
+  priv = widget->priv;
+  
+  /* updates style context if it exists already */
+  path = gtk_widget_get_path (widget);
+
+  if (G_UNLIKELY (priv->context == NULL))
     {
       GdkScreen *screen;
 
-      widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
-                                            "direction", gtk_widget_get_direction (widget),
-                                            NULL);
+      priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
+                                    "direction", gtk_widget_get_direction (widget),
+                                    NULL);
 
       g_signal_connect (widget->priv->context, "changed",
                         G_CALLBACK (style_context_changed), widget);
@@ -14346,18 +14354,9 @@ gtk_widget_get_style_context (GtkWidget *widget)
       screen = gtk_widget_get_screen (widget);
 
       if (screen)
-        gtk_style_context_set_screen (widget->priv->context, screen);
+        gtk_style_context_set_screen (priv->context, screen);
 
-      _gtk_widget_update_path (widget);
-      gtk_style_context_set_path (widget->priv->context,
-                                  widget->priv->path);
-    }
-  else
-    {
-      /* Force widget path regeneration if needed, the
-       * context will be updated within this function.
-       */
-      gtk_widget_get_path (widget);
+      gtk_style_context_set_path (priv->context, path);
     }
 
   return widget->priv->context;